<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail" v-enterToNext>
        <div style="color: orange; padding-right: 40px; text-align: right;">
          {{ $t('说明：0表示不限额') }}
        </div>
        <a-row>
          <a-col :span="24">
            <div style="font-weight: 600; color: #000; font-size: 15px; padding-left: 40px">
              {{ $t('会员最大消费额度') }}
            </div>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item
              :label="$t('每日')"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="mDayConsumeLimit"
            >
              <a-input
                v-model="model.mDayConsumeLimit"
                :placeholder="$t('会员每日最大消费额度')"
                oninput="value=value.replace(/\D/g,''); if(value.length > 9)value = value.slice(0, 9)"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item
              :label="$t('每月')"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="mMonthConsumeLimit"
            >
              <a-input
                v-model="model.mMonthConsumeLimit"
                :placeholder="$t('会员每月最大消费额度')"
                oninput="value=value.replace(/\D/g,''); if(value.length > 9)value = value.slice(0, 9)"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <div style="font-weight: 600; color: #000; font-size: 15px; padding-left: 40px">
              {{ $t('会员最大线上支付额度') }}
            </div>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item
              :label="$t('每日')"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="mDayOnlinePayLimit"
            >
              <a-input
                v-model="model.mDayOnlinePayLimit"
                :placeholder="$t('会员每日最大线上支付额度')"
                oninput="value=value.replace(/\D/g,''); if(value.length > 9)value = value.slice(0, 9)"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item
              :label="$t('每月')"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="mMonthOnlinePayLimit"
            >
              <a-input
                v-model="model.mMonthOnlinePayLimit"
                :placeholder="$t('会员每月最大线上支付额度')"
                oninput="value=value.replace(/\D/g,''); if(value.length > 9)value = value.slice(0, 9)"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <div style="font-weight: 600; color: #000; font-size: 15px; padding-left: 40px">
              {{ $t('会员最大投币值') }}
            </div>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item
              :label="$t('每日')"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="mDaySlotCoinLimit"
            >
              <a-input
                v-model="model.mDaySlotCoinLimit"
                :placeholder="$t('会员每日最大投币值')"
                oninput="value=value.replace(/\D/g,''); if(value.length > 9)value = value.slice(0, 9)"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item
              :label="$t('每月')"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="mMonthSlotCoinLimit"
            >
              <a-input
                v-model="model.mMonthSlotCoinLimit"
                :placeholder="$t('会员每月最大投币值')"
                oninput="value=value.replace(/\D/g,''); if(value.length > 9)value = value.slice(0, 9)"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <div style="font-weight: 600; color: #000; font-size: 15px; padding-left: 40px">
              {{ $t('会员最大投A币值') }}
            </div>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item
              :label="$t('每日')"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="mDaySlotACoinLimit"
            >
              <a-input
                v-model="model.mDaySlotACoinLimit"
                :placeholder="$t('会员每日最大投A币值')"
                oninput="value=value.replace(/\D/g,''); if(value.length > 9)value = value.slice(0, 9)"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item
              :label="$t('每月')"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="mMonthSlotACoinLimit"
            >
              <a-input
                v-model="model.mMonthSlotACoinLimit"
                :placeholder="$t('会员每月最大投A币值')"
                oninput="value=value.replace(/\D/g,''); if(value.length > 9)value = value.slice(0, 9)"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <div style="font-weight: 600; color: #000; font-size: 15px; padding-left: 40px">
              {{ $t('会员过户最大值') }}
            </div>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item
              :label="$t('存币')"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="mTransferCoinLimit"
            >
              <a-input
                v-model="model.mTransferCoinLimit"
                :placeholder="$t('会员过户存最大币值')"
                oninput="value=value.replace(/\D/g,''); if(value.length > 9)value = value.slice(0, 9)"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item
              :label="$t('存票')"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="mTransferLotteryLimit"
            >
              <a-input
                v-model="model.mTransferLotteryLimit"
                :placeholder="$t('会员过户存最大票值')"
                oninput="value=value.replace(/\D/g,''); if(value.length > 9)value = value.slice(0, 9)"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item
              :label="$t('存A币')"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="mTransferACoinLimit"
            >
              <a-input
                v-model="model.mTransferACoinLimit"
                :placeholder="$t('会员过户存最大A币值')"
                oninput="value=value.replace(/\D/g,''); if(value.length > 9)value = value.slice(0, 9)"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item
              :label="$t('存A票')"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="mTransferALotteryLimit"
            >
              <a-input
                v-model="model.mTransferALotteryLimit"
                :placeholder="$t('会员过户存最大A票值')"
                oninput="value=value.replace(/\D/g,''); if(value.length > 9)value = value.slice(0, 9)"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <div style="font-weight: 600; color: #000; font-size: 15px; padding-left: 40px">{{ $t('机台') }}</div>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item :label="$t('退币')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gameReturnCoin">
              <j-switch v-model="model.gameReturnCoin" :options="options"></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item
              :label="$t('退A币')"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="gameReturnACoin"
            >
              <j-switch v-model="model.gameReturnACoin" :options="options"></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item
              :label="$t('投A票')"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="gameInputALottery"
            >
              <j-switch v-model="model.gameInputALottery" :options="options"></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <div style="font-weight: 600; color: #000; font-size: 15px; padding-left: 40px">{{ $t('其他') }}</div>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item :label="$t('票转币')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lotteryToCoin">
              <j-switch v-model="model.lotteryToCoin" :options="options"></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item :label="$t('A票转币')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="aLotteryToCoin">
              <j-switch v-model="model.aLotteryToCoin" :options="options"></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item :label="$t('管理端账户修正')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mAccountEditMgt">
              <j-switch v-model="model.mAccountEditMgt" :options="options"></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" :offset="2">
            <a-form-model-item :label="$t('吧台账户修正')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mAccountEditBar">
              <j-switch v-model="model.mAccountEditBar" :options="options"></j-switch>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'OperationalParamSettingsForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      model: {},
      options:[1,0],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        mDayConsumeLimit: [{ required: true, message: this.$t('请输入会员每日最大消费额度') }],
        mMonthConsumeLimit: [{ required: true, message: this.$t('请输入会员每月最大消费额度') }],
        mDayOnlinePayLimit: [{ required: true, message: this.$t('请输入会员每日最大线上支付额度') }],
        mMonthOnlinePayLimit: [{ required: true, message: this.$t('请输入会员每月最大线上支付额度') }],
        mDaySlotCoinLimit: [{ required: true, message: this.$t('请输入会员每日最大投币值') }],
        mMonthSlotCoinLimit: [{ required: true, message: this.$t('请输入会员每月最大投币值') }],
        mDaySlotACoinLimit: [{ required: true, message: this.$t('请输入会员每日最大投A币值') }],
        mMonthSlotACoinLimit: [{ required: true, message: this.$t('请输入会员每月最大投A币值') }],
        mTransferCoinLimit: [{ required: true, message: this.$t('请输入会员过户存最大币值') }],
        mTransferLotteryLimit: [{ required: true, message: this.$t('请输入会员过户存最大票值') }],
        mTransferACoinLimit: [{ required: true, message: this.$t('请输入会员过户存最大A币值') }],
        mTransferALotteryLimit: [{ required: true, message: this.$t('请输入会员过户存最大A票值') }],
        gameReturnCoin: [{ required: true, message: this.$t('') }],
        gameReturnACoin: [{ required: true, message: this.$t('') }],
        gameInputALottery: [{required: true, message: this.$t('')}],
        lotteryToCoin:[{ required: true, message: this.$t('') }],
        aLotteryToCoin:[{ required: true, message: this.$t('') }],
        mAccountEditMgt:[{ required: true, message: this.$t('') }],
        mAccountEditBar:[{ required: true, message: this.$t('') }],
      },
      params:[]
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {},
  methods: {
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
      if (this.model.id) {
        this.disable = true
        this.getShopParam()
      }
    },
    getShopParam(){
      let that=this
      getAction('/bis/bisSysParameter/getShopParam',{pageSize:100,tenantId:that.model.tenantId}).then(res=>{
        if(res.success){
          that.params=res.result.records
          that.params.forEach(ps=>{
            if(ps.name=='gameReturnCoin'||ps.name=='gameReturnACoin'||ps.name=='lotteryToCoin'
            ||ps.name=='aLotteryToCoin'||ps.name=='gameInputALottery'||ps.name=='mAccountEditMgt'
            ||ps.name=='mAccountEditBar'){
              that.$set(that.model,ps.name,ps.ivalue)
            }else{
              that.$set(that.model,ps.name,ps.svalue)
            }
          })
        }
      })
    },
    submitForm() {
      let that = this
      // 触发表单验证
      that.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = '/bis/bisSysParameter/saveBatch'
          let method = 'POST'
          let arr=[]
          that.params.forEach(ps=>{
            let dtl={}
            if(ps.name=='gameReturnCoin'||ps.name=='gameReturnACoin'||ps.name=='lotteryToCoin'
            ||ps.name=='aLotteryToCoin'||ps.name=='gameInputALottery'||ps.name=='mAccountEditMgt'
            ||ps.name=='mAccountEditBar'){
              dtl=Object.assign({},ps,{
                ivalue:that.model[ps.name]
              })
              console.log(dtl)
            }else{
              dtl=Object.assign({},ps,{
                svalue:that.model[ps.name]
              })
            }
            arr.push(dtl)
          })
          httpAction(httpurl, arr, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },
  },
}
</script>